<?php
/**
 * 分类管理
 * Created by PhpStorm.
 * User: Administrator
 * Date: 15-6-17
 * Time: 下午2:37
 */
namespace app\modules\cn\controllers;


use app\libs\IeltsController;
use app\libs\Method;
use app\modules\cn\models\CaseList;
use app\modules\cn\models\Info;
use app\modules\content\models\Classes;
use app\modules\content\models\Recommend;
use app\modules\content\models\Teachers;

class TeacherController extends IeltsController
{
    public $enableCsrfValidation = false;
    public $layout = 'cn';


    public function actionIndex()
    {
        $page = \Yii::$app->request->get('page',1);
        $seniority = \Yii::$app->request->get('seniority');
        $subject = \Yii::$app->request->get('subject');
        $data = Teachers::getTeacher($seniority, $subject,$page,15);
        $time = time();
        $recommend = Info::find()->asArray()->where('cate=2 and pushTime<=' . $time)->orderBy('sort asc,id desc')->limit(4)->all();
        $course = Classes::find()->asArray()->limit(3)->orderBy('viewCount desc')->all();
        $focus = Recommend::find()->asArray()->where('type=2')->orderBy('sort asc,id desc')->limit(8)->all();
        $case = CaseList::find()->asArray()->limit(6)->orderBy('id desc')->all();
        $count =Teachers::find()->asArray()->count();
        $countPage= $count!=false?ceil($count/15):0;
        $pageArray = Method::page($countPage, $page);
        $wx['chat'] = \Yii::$app->params['chat_wx'][6][date("w")];
        $wx['image'] = \Yii::$app->params['chat_wx']['image6'][date("w")];
        $this->title = '申友雅思在线_雅思名师团队_学雅思一对一';
        $this->keywords = '雅思名师,名师指导,学雅思一对一';
        $this->description = '申友雅思名师团队，雅思名师帮助考生高效提分，申友雅思在线';
        return $this->render('index', ['data' => $data,'recommend'=>$recommend,'course'=>$course,'focus'=>$focus,'case'=>$case,'pageArray'=>$pageArray,'page'=>$page,'wx'=>$wx]);
    }
    public function actionDetail()
    {
        $id = \Yii::$app->request->get('id');
        $time=time();
        $detail = Teachers::find()->asArray()->where('id='.$id)->one();
        $recommend = Info::find()->asArray()->where('cate=2 and pushTime<=' . $time)->orderBy('sort asc,id desc')->limit(4)->all();
        $teacher= Teachers::find()->asArray()->orderBy('sort asc')->limit(6)->all();
        $article = Info::find()->asArray()->where('cate=5 and author="'.$detail['name'].'"')->orderBy('id desc')->limit(10)->all();
        $case = CaseList::find()->asArray()->limit(6)->orderBy('id desc')->all();
        $this->title = '申友雅思在线_' . $detail['name'] . '老师专栏';
        $this->keywords = $detail['subject'];
        $this->description = mb_substr(strip_tags($detail['introduction']), 0, 100);
        return $this->render('detail', ['detail'=>$detail,'recommend'=>$recommend,'teacher'=>$teacher,'article'=>$article,'case'=>$case]);
    }


}